package com.example.test.controller;


import com.alibaba.fastjson.JSONObject;
import com.example.test.bean.BraendType;
import com.example.test.bean.DTO.input.CustomersCreateInputDTO;
import com.example.test.bean.DTO.input.CustomersUpdateInputDTO;
import com.example.test.bean.DTO.input.UsersCreateInputDTO;
import com.example.test.bean.DTO.input.UsersUpdateInputDTO;
import com.example.test.common.model.PageModel;
import com.example.test.common.model.R;
import com.example.test.common.token.LoginToken;
import com.example.test.service.CustomersService;
import com.example.test.service.UsersService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 客户信息表 前端控制器
 * </p>
 *
 * @author dz
 * @since 2022-04-10
 */
@CrossOrigin
@RestController
@RequestMapping("/customers")
public class CustomersController {
    @Resource
    private CustomersService customersService;
    @LoginToken
    @ApiOperation(value = "商品信息表根据keyword分页查询")
    @PostMapping("/getByKeyword")
    public R customList(@RequestBody JSONObject jsonParam) {
        System.out.println(jsonParam.toJSONString());
        String keyword = jsonParam.getString("keyword");
        Long size = Long.valueOf(jsonParam.getString("size"));
        Long current = Long.valueOf(jsonParam.getString("current"));
        PageModel pageModel = new PageModel();
        pageModel.setCurrent(current);
        pageModel.setSize(size);
        return customersService.getCustomByKeyword(keyword,pageModel);
    }
    @LoginToken
    @ApiOperation(value = "根据id分页查询")
    @PostMapping("/getCustomer")
    public R listById(@RequestBody JSONObject jsonParam) {
        System.out.println(jsonParam.toJSONString());
        Long customerId = jsonParam.getLong("customerId");
        return customersService.getCustomById(customerId);
    }
    @LoginToken
    @ApiOperation(value = "添加")
    @PostMapping(value = "/insert")
    public R insert(@RequestBody CustomersCreateInputDTO customersCreateInputDTO) {
        return customersService.addCustom(customersCreateInputDTO);
    }
    @LoginToken
    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public R update(@RequestBody CustomersUpdateInputDTO customersUpdateInputDTO) {
        return customersService.updateCustom(customersUpdateInputDTO);
    }
    @LoginToken
    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@RequestBody JSONObject jsonParam) {
        System.out.println(jsonParam.toJSONString());
        Long customerId = jsonParam.getLong("customerId");
        return customersService.deleteCustom(customerId);
    }

}

